/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.ufpr.tads.Rent.view;

import br.ufpr.tads.Rent.model.DevolveDAO;
import br.ufpr.tads.Rent.view.ModeloTabelaDevolucao;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author vheofacker
 */
public class Devolucoes extends javax.swing.JFrame {
    private ModeloTabelaDevolucao tabeladevolucao;
    /**
     * Creates new form Locacao
     */
    public Devolucoes() {
         tabeladevolucao = new ModeloTabelaDevolucao();
         bucar();
        initComponents();
    }
    public void bucar(){
      
          try {
            DevolveDAO veiculos = new DevolveDAO();
            tabeladevolucao.setListaDevolucao(veiculos.SelecionaDevolucao());
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        buscalocados = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        TabelaDevolucao = new javax.swing.JTable();
        jLabel7 = new javax.swing.JLabel();
        devolve = new javax.swing.JButton();

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel2.setText("Mostrar Veiculos locados");

        buscalocados.setText("Buscar");
        buscalocados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscalocadosActionPerformed(evt);
            }
        });

        TabelaDevolucao.setModel(tabeladevolucao);
        TabelaDevolucao.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TabelaDevolucaoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(TabelaDevolucao);

        devolve.setText("Devolver Selecionado");
        devolve.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                devolveActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(490, Short.MAX_VALUE)
                    .addComponent(jLabel7)
                    .addGap(40, 40, 40))
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(51, 51, 51)
                            .addComponent(jLabel2)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(buscalocados)
                    .addGap(119, 119, 119)))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(devolve)
                .addContainerGap())
            .addComponent(jScrollPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(14, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(buscalocados)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(devolve)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buscalocadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscalocadosActionPerformed
      /*  try {
            DevolveDAO veiculos = new DevolveDAO();
            tabeladevolucao.setListaDevolucao(veiculos.SelecionaDevolucao());
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        }*/
    }//GEN-LAST:event_buscalocadosActionPerformed

    private void devolveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_devolveActionPerformed
        DevolveDAO dev;
        try {
            dev = new DevolveDAO();
            int id = Integer.parseInt(TabelaDevolucao.getValueAt(TabelaDevolucao.getSelectedRow(), 0).toString());
            dev.devolucao(id);
            bucar();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Devolucoes.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_devolveActionPerformed

    private void TabelaDevolucaoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TabelaDevolucaoMouseClicked
        
    
    }//GEN-LAST:event_TabelaDevolucaoMouseClicked

    /**
     * @param args the command line arguments
     */


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable TabelaDevolucao;
    private javax.swing.JButton buscalocados;
    private javax.swing.JButton devolve;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable2;
    // End of variables declaration//GEN-END:variables
}
